package com.hnguigu.health.houduan.jpx.controller_jpx;

import com.hnguigu.health.houduan.jpx.service_jpx.TMemberExaminationSer;
import com.hnguigu.health.houduan.jpx.service_jpx.TMemberInfoSer;
import com.hnguigu.health.houduan.jpx.service_jpx.TMemberSer;
import com.hnguigu.health.houduan.jpx.service_jpx.TOrderSer;
import com.hnguigu.health.mapper.TMemberMapper;
import com.hnguigu.health.pojo.TMember;

import com.hnguigu.health.pojo.TMemberExamination;
import com.hnguigu.health.pojo.TOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;


@Controller
@RequestMapping("/TMemberController")
public class TMemberController {
    @Autowired(required = false)
    TMemberMapper tMemberMapper;
    @Autowired(required = false)
    TMemberSer tMemberSer;
    @Autowired(required = false)
    TMemberInfoSer tMemberInfoSer;
    @Autowired(required = false)
    TOrderSer tOrderSer;
    @Autowired(required = false)
    TMemberExaminationSer tMemberExaminationSer;


    String name ="风奶奶";
    String sex ="0";
    String phonenumbr ="65448946416";
    String idcard ="430522020010723";
    String btirthday ="2002-07-23";
    String maritalStatus ="1";

    //1.3A `t_member` 体检预约提交套餐 添加 会员的信息tMemberSerc表,tMemberExaminationSer表,t_order表
    @RequestMapping("/TmemberUpdate")
    public int TMemberAdd(String name, String sex, String phonenumber, String idcard, String birthday,Integer maritalStatus,
                          Integer setmealID, String examDate) throws ParseException {
        TMember tMember = new TMember();
        tMember.setId(97);
        tMember.setFilenumber("20190308012");
        tMember.setName("徐风年");
        tMember.setSex("1");
        tMember.setPhonenumber("15573989328");
        tMember.setIdcard("430522020010724");

        tMember.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse("2002-07-24"));
        tMember.setCreatetime( new SimpleDateFormat("yyyy-MM-dd").parse("2022-04-011"));
        int i = tMemberSer.TmenmberUpdate(tMember);
        System.out.println("会员信息"+i);

      /* TMember tMember1 = tMemberMapper.selectByPrimarycardID(idcard); 语句未删除
        System.out.println(tMember1);*/
        //1.3B tmemberexamination 会员检查表 同时添加会员的,会员编号,套餐id号,体检日期,
        TMemberExamination tMemberExamination = new TMemberExamination();
        tMemberExamination.setTMemberId(97);      //tMember1.getId()
        tMemberExamination.setTSetmealId(12);
        tMemberExamination.setReportStatus(0);
        tMemberExamination.setExamDate("2022-04-11");
        tMemberExamination.setCreatetime("2022-04-11");
        int i1 = tMemberExaminationSer.TMemberExaminationAdd(tMemberExamination);

        TOrder tOrder = new TOrder();
        tOrder.setMemberId(97);
        tOrder.setOrderdate("2022-04-11");
        tOrder.setOrdertype("PC端预约");
        tOrder.setOrderstatus("0");
        tOrder.setSetmealId(12);
        int i2 = tOrderSer.TOrderAdd(tOrder);

        return i1;
        //A 注册,根据账号,密码(存储vuex) 查对象,拿id修改/会员编号(存储vuex),套餐id号 添加
    }
    //2.1 t_tmember 会员表 报告查询登录 ok

    //A注册
    @RequestMapping("/loginA")
    @ResponseBody
    public int LoginA(TMember tMember) {
        System.out.println("*******************************登录***********************");
        TMember tMember1 = new TMember();
        tMember.setId(0);
        tMember.setEmail(tMember.getEmail());
        tMember.setPassword(tMember.getPassword());
         int i  = tMemberSer.loginA(tMember1);
        return  i;
    }

    @RequestMapping("/loginB")
    public int login(TMember lo){
        TMember tMember = new TMember();
        tMember.setEmail("zhangsan@163.com");
        tMember.setPassword("1234");
        TMember login = tMemberSer.loginB(tMember);
        // TMember login = tMemberSer.login("zhangsan@163.com", "1234");
        System.out.println(login);
        if(login!=null){
            System.out.println("登录成功");
        }
        return 0;
    }
    //2.2 t_tmember 会员表,tmemberexamination 会员检查表 据tmember_id连接查询 (一个人可能有两个套餐 可能要放数组) o
    @RequestMapping("/TMemberExamination_and_TmemberFind")
    public List<TMemberExamination> TMemberExamination_and_TmemberFind(Integer tMemberId) {
        List<TMemberExamination> tMemberExaminations = tMemberExaminationSer.TMemberExamination_and_TmemberFind(97);
        return tMemberExaminations;
    }


    @GetMapping("tt")
    @ResponseBody
    public int m(){
        return 1;
    }
}
